// pages/Announcement/announcement.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gonggaotrue:true,
    biaotiinput:'',
    neironginput:'',
    page:1,
    allPage:'',
    listData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (type) {
    let that = this;
    if (type == 1) {
    } else {
      that.setData({
        page: 1
      })
    }
    var groupId = wx.getStorageSync("qundetail")
    var data = {
      paraUrl: 'bulletin/page/group?groupId=' + groupId + '&page=' + that.data.page+'&size=6',
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        if (type == 1) {
          var listData = that.data.listData.concat(res.data.body.content)
        } else {
          var listData = res.data.body.content
        }
        that.setData({
          listData: listData,
          allPage: res.data.body.totalElements
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.page < that.data.allPage) {
      that.setData({
        page: that.data.page + 1
      })
      that.onShow(1);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  xinjiangonggao:function(){
    this.setData({
      gonggaotrue: false
    });
  },
  cancel:function(){
    this.setData({
      gonggaotrue: true
    });
  },
  // 获取输入框的值
  biaotiinput: function (e) {
    this.setData({
      biaotiinput: e.detail.value
    })
  },
  // 获取输入框的值
  neironginput: function (e) {
    this.setData({
      neironginput: e.detail.value
    })
  },
  confirm: function () {
    let that = this;
    var groupId = wx.getStorageSync("qundetail")
    var data = {
      paraUrl: 'bulletin/create?groupId=' + groupId + '&name=' + that.data.biaotiinput + '&content=' + that.data.neironginput,
      paraData: ''
    }
    if (that.data.biaotiinput == "" || that.data.neironginput == "" ) {
      wx.showToast({
        title: '请将数据填写完整',
        icon: 'success',
        image: '/images/shibai.png',
        duration: 2000
      })
      return;
    }
    app.postRequest(data, function (res) {
      if (res.data.result == 200) {
        wx.showToast({
          title: '新建成功',
          icon: 'success',
          duration: 2000
        })
        that.onShow();
      } else {
        wx.showToast({
          title: '新建失败',
          icon: 'success',
          image: '/images/shibai.png',
          duration: 2000
        })
      }
    })
    this.setData({
      gonggaotrue: true
    });
  },
  xiangqing(data) {
    var that = this;
    console.log(data)
    wx.setStorageSync('AnnouncementDetail', data.currentTarget.dataset.type)
    wx.navigateTo({
      url: '/pages/AnnouncementDetail/AnnouncementDetail',
    })
  }
})